<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //起步价13（3公里内），之后每多一公里加5元，输入公里数得到价格
        //如果有拥堵情况，总价格多收取10元钱拥堵费
        var car = (function () {
            var start = 13; //起步价
            var total = 0; //总价
            return {
                price: function (n) {
                    if (n <= 3) {
                        total = start;
                    } else {
                        total = start + (n - 3) * 5;
                    }
                    return total;
                },
                yd: function (flag) {
                    return flag ? total + 10 : total;
                }

            }
        })();
        var price = car.price(5);
        price = car.yd(true);
        console.log(price);
    </script>
</body>

</html>